package cn.dubito.seller.sign;

import cn.dubito.seller.service.SignService;
import cn.dubito.util.RSAUtil;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @author liliang
 * @description: AOP 验证签名
 * @date 2018/5/29.
 */
@Aspect
@Component
public class SignAop {

    @Autowired
    private SignService signService;

    @Before(value = "execution(* cn.dubito.seller.controller.*.*(..)) && args(authId,sign,text)", argNames = "authId,sign,text")
    public void verify(String authId, String sign, SignText text) {
        String publicKey = signService.getPublicKey(authId);
        Assert.isTrue(RSAUtil.verify(text.toText(), sign, publicKey), "验签失败");
    }
}
